Skip to content

backup-state and restore-state subcommands to use bonsai#9812

Closed
macfarla wants to merge 2 commits intobesu-eth:mainfrom
macfarla:fix/backup-state-subcommand-class-cast-ex
Closed

backup-state and restore-state subcommands to use bonsai#9812
macfarla wants to merge 2 commits intobesu-eth:mainfrom
macfarla:fix/backup-state-subcommand-class-cast-ex

Conversation

@macfarla
Copy link
Copy Markdown
Contributor

PR description

Both BackupState.java and RestoreState.java explicitly cast the world state archive to ForestWorldStateArchive and use Forest-specific APIs (trie traversal via StoredMerklePatriciaTrie.visitLeafs, PersistVisitor/RestoreVisitor for trie reconstruction). Since
Forest is deprecated and Bonsai is the default, thus these commands are effectively broken for all default-configuration nodes.

Proposed Fix

Replace Forest world state access with Bonsai flat DB APIs:

  • Backup: Use BonsaiWorldStateKeyValueStorage.streamFlatAccounts() and streamFlatStorages() to iterate accounts and storage instead of Forest trie traversal
  • Restore: Use BonsaiWorldStateKeyValueStorage.Updater.putAccountInfoState(), putCode(), and putStorageValueBySlotHash() to write flat DB entries instead of Forest trie reconstruction
  • Backup file format: Unchanged — the RLP structure ([accountHash, accountRlp, code] + storage entries + empty-list terminator) remains the same

Fixed Issue(s)

fixes #9811

Thanks for sending a pull request! Have you done the following?

  • Checked out our contribution guidelines?
  • Considered documentation and added the doc-change-required label to this PR if updates are required.
  • Considered the changelog and included an update if required.
  • For database changes (e.g. KeyValueSegmentIdentifier) considered compatibility and performed forwards and backwards compatibility tests

Locally, you can run these tests to catch failures early:

  • spotless: ./gradlew spotlessApply
  • unit tests: ./gradlew build
  • acceptance tests: ./gradlew acceptanceTest
  • integration tests: ./gradlew integrationTest
  • reference tests: ./gradlew ethereum:referenceTests:referenceTests
  • hive tests: Engine or other RPCs modified?

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
@macfarla
Copy link
Copy Markdown
Contributor Author

Re the failing AcceptanceTest: the test data archive is a Forest-format database, but our code now requires Bonsai. The checkArgument(worldStateArchive instanceof BonsaiWorldStateProvider, ...) fails when the node starts with Forest data.
this test does a full backup → restore → re-backup round-trip. The failure is because:

  1. The test data archive (version1/besu-db-archive.tar.gz) contains a Forest-format database
  2. The test framework defaults to DEFAULT_FOREST_CONFIG
  3. Our code now requires BonsaiWorldStateProvider, so the checkArgument fails and the backup node exits with code 1

The chain data (blocks, headers, receipts) is format-agnostic, but the world state in the archive is stored as Forest trie nodes, which a Bonsai-configured node can't read.

Options:

  1. Generate a new Bonsai test data archive — replace version1/besu-db-archive.tar.gz with one containing a Bonsai DB. This requires running a node to create it.
  2. Restructure the test — instead of using a pre-built archive, have the test create a fresh Bonsai node in dev mode, mine some blocks, then test backup/restore on that. This eliminates the dependency on Ropsten data.
  3. Support both formats — detect whether the world state is Forest or Bonsai and use the appropriate APIs. This adds complexity but keeps backward compatibility.

@macfarla macfarla marked this pull request as draft February 16, 2026 03:18
@macfarla
Copy link
Copy Markdown
Contributor Author

closing this since the fact this is still on forest is clear indication it's not being used. will remove in a new PR

@macfarla macfarla closed this Feb 17, 2026
@macfarla macfarla deleted the fix/backup-state-subcommand-class-cast-ex branch February 18, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backup and restore state subcommands do not support bonsai

1 participant